home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9093 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.9 KB

  1. Path: news.unt.edu!news
  2. From: Steve Fogoros <sfogoros@hsc.unt.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Data Name to Pointer Question
  5. Date: Wed, 06 Mar 1996 23:18:35 -0800
  6. Organization: University of North Texas Health Science Center
  7. Message-ID: <313E8DCB.922@hsc.unt.edu>
  8. References: <4hkhtb$epm@theopolis.orl.mmc.com>
  9. NNTP-Posting-Host: sfogoros.hsc.unt.edu
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win16; I)
  14.  
  15. Steve Woodcock wrote:
  16. > Hello All:
  17. >    Apologies in advance is this is so mind-bogglingly simple that I'm
  18. > somehow missing it.
  19. >    I have a data file containg the name of a structure called
  20. > "process one", as such
  21. > #
  22. > # comments
  23. > #
  24. > process_one
  25. > #
  26. > # comments
  27. >    Over in the program itself, "process one" is a data structure filled
  28. > with information.
  29. >    Is there a way for me to convert the string "process one" that I read
  30. > in from the data file to a pointer pointing to the actual structure
  31. > "process one"?  Essentially, I want to turn the contents of this string
  32. > variable into the *name* of the variable I want to access.
  33.  
  34. I saw an inplementation similar to what you describe, in a ProCom unix port written by a man at Fort Hood 
  35. in Kilene, Texas. He stored function names and pointers for the program's menus. At run time you selected 
  36. a function from the menu. This made it easier to maintain the menu lists because they were all in one 
  37. place. A small dispatch function would display the menu and accept selection. He also switched menu lists 
  38. based on user selection. (If anybody knows offhand where I can get it again? I had to leave it at a 
  39. company that I had to leave.)
  40.  
  41. The basic idea is to create a structure (slst) to hold the text name of a data structure and pointer to 
  42. it. You have to do this in the source because you will loose the declared name when you compile. Declare a 
  43. static array of slst and initialize it with the data structure names and pointers in your program that you 
  44. expect to find in the file. As you acquire a name out of file, strcmp() it against the names in slst[]. If 
  45. you match the name, you will then have a pointer to the actual structure.
  46.  
  47. I have a question for you. Do your data structures all have the same names and types for members? Once you 
  48. have a pointer to a data structure, how will you access member elements? If they are all the same you 
  49. should have no problem. You can hardwire the member names. If your structures have different names and 
  50. types for members, I'm not sure how to access a member element. (Maybe char by char?)
  51.  
  52. I would like to know more about the specific nature of your data structures because you may need to 
  53. re-think the relationship between your data structures and your driver file. (Since I'm in the dark here, 
  54. you may also be right on track.)
  55.  
  56. -- 
  57. Steve Fogoros, Academic Information Coordinator
  58. University of North Texas Health Science Center
  59. sfogoros@hsc.unt.edu
  60.